﻿using AutoMapper;
using DearlerPlatform.Core.Repository;
using DearlerPlatform.Domain.Entity;
using DearlerPlatform.Service.CustomerApp.Views;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DearlerPlatform.Service.CustomerApp
{
    public partial class CustomerService : ICustomerService
    {
        private readonly IRepository<Customers> _customerRepo;
        private readonly IRepository<Customerinvoices> _customerInvoiceRepo;
        private readonly IRepository<Customerpwds> _customerPwdRepo;
        private readonly IMapper _mapper;

        public CustomerService(IRepository<Customers> customerRepo, IRepository<Customerinvoices> customerInvoiceRepo, IRepository<Customerpwds> customerPwdRepo,IMapper mapper)
        {
            this._customerRepo = customerRepo;
            this._customerInvoiceRepo = customerInvoiceRepo;
            this._customerPwdRepo = customerPwdRepo;
            this._mapper = mapper;
        }

        /// <summary>
        /// 根据用户名获取用户信息
        /// </summary>
        /// <param name="customerNo">用户名</param>
        /// <returns>用户信息</returns>
        public async Task<CustomerLoginVM> GetCustomerByNoAsync(string customerNo)
        {
            var customer = await _customerRepo.GetAsync(m=>m.Customerno == customerNo);
            var customerVM = _mapper.Map<Customers, CustomerLoginVM>(customer); 
            return customerVM;
        }

        /// <summary>
        /// 根据ID获取用户信息
        /// </summary>
        /// <param name="id">用户ID</param>
        /// <returns>用户VM</returns>
        public CustomerLoginVM GetCustomerById(long id)
        {
            var customer = _customerRepo.Get(m => m.Id == id);
            var customerVM = _mapper.Map<Customers, CustomerLoginVM>(customer);
            return customerVM;
        }
    }
}
